package com.gserver.commons.quartz;

import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.Trigger;
import org.springframework.utils.SpringContextHolder;


public class SchedulerManager {
	private static SchedulerManager instance;

	public static SchedulerManager getInstance() {
		if (instance == null) {
			instance = SpringContextHolder.getBean(SchedulerManager.class);
		}
		return instance;
	}

	private Scheduler quartzScheduler;

	public Scheduler getQuartzScheduler() {
		return quartzScheduler;
	}

	public void setQuartzScheduler(Scheduler quartzScheduler) {
		this.quartzScheduler = quartzScheduler;
	}

	public void addCronTask(JobDetail job, Trigger trigger) {
		try {
			quartzScheduler.scheduleJob(job, trigger);
		} catch (SchedulerException e) {
			e.printStackTrace();
		}
	}
}
